package receivers;

import services.LeaveRoomService;
import tw.edu.tku.im.maze.Room;
import tw.edu.tku.im.maze.RoomListRep;
import tw.edu.tku.im.maze.UpdateRoomRep;

import com.example.maze.ConnectionInfo;
import com.example.maze.LobbyActivity;
import com.example.maze.RoomActivity;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public class UpdateRoomStatusRepReceiver extends BroadcastReceiver {
   Activity currentUIActivity;
   
   //[ -------------------- construct --------------------
   public UpdateRoomStatusRepReceiver(Activity activity) {
      this.currentUIActivity= activity;
   }
   //[ -------------------- construct --------------------

   // --------------------------------------------------
   @Override
   public void onReceive(Context context, Intent intent) {
      UpdateRoomRep roomStatus= (UpdateRoomRep)intent.getParcelableExtra("packet");      
      if(roomStatus.getRoomSurvive()) {
         ((RoomActivity)currentUIActivity).update(roomStatus.getTeam1(),
                                                  roomStatus.getStart(),
                                                  roomStatus.getRoomName(),
                                                  roomStatus.getMapLv(),
                                                  roomStatus.getMap());         
      } else {
         context.startService(new Intent(context, LeaveRoomService.class));
         currentUIActivity.startActivity(new Intent(currentUIActivity, LobbyActivity.class));  
      }             
   }
   // --------------------------------------------------

}
